<template>
  <div class="worth">
    <div class="title">
      <img class="logo" src="@/pages/Worth/images/值得买.png" />
      <div class="text">严选好物 用心生活</div>
    </div>
    <!--轮播图 -->
    <div class="swiperBox">
      <van-swipe width="90">
        <!-- <van-swipe-item  v-for="(item, index) in navList" :key="index">
          <div class="info" v-if="index * 2 < navList.length ">
            <img class="pic" :src="navList[index * 2]['picUrl']" />
            <div class="main">{{ navList[index * 2]['mainTitle'] }}</div>
            <div class="vice">{{ navList[index * 2]['viceTitle'] }}</div>
          </div>
          <div class="info" v-if="index * 2 < navList.length ">
            <img class="pic" :src="navList[index * 2 + 1]['picUrl']" />
            <div class="main">{{ navList[index * 2 + 1]['mainTitle'] }}</div>
            <div class="vice">{{ navList[index * 2 + 1]['viceTitle'] }}</div>
          </div> -->
        <van-swipe-item v-for="(item, index) in navItem" :key="index">
          <div class="info">
            <img class="pic" :src="item[0].picUrl" />
            <div class="main">{{ item[0].mainTitle }}</div>
            <div class="vice">{{ item[0].viceTitle }}</div>
          </div>
          <div class="info">
            <img class="pic" :src="item[1].picUrl" />
            <div class="main">{{ item[1].mainTitle }}</div>
            <div class="vice">{{ item[1].viceTitle }}</div>
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
    <!-- 瀑布流列表 -->
    <div class="looksList" v-for="(item, index) in lookList" :key="index">
      <div class="look">
        <img class="lookImg" :src="item.picUrl" />
        <div class="lookTitle">{{ item.title }}</div>
        <div class="topics">
          <div class="topicsName">
            <img class="topicsImg" :src="item.avatar" />
            <div class="nickname">{{ item.nickname }}</div>
          </div>
          <div class="readCount">
            <van-icon name="eye-o" />
            <div class="num">{{ item.readCount }}</div>
          </div>
        </div>
      </div>
      <div class="look">
        <img class="lookImg" :src="item.picUrl" />
        <div class="lookTitle">{{ item.title }}</div>
        <div class="topics">
          <div class="topicsName">
            <img class="topicsImg" :src="item.avatar" />
            <div class="nickname">{{ item.nickname }}</div>
          </div>
          <div class="readCount">
            <van-icon name="eye-o" />
            <div class="num">{{ item.readCount }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reqWorthSwiper, reqWorthLook } from "@/api";
import vueWaterfallEasy from "vue-waterfall-easy";
export default {
  data() {
    return {
      navList: [], //轮播数据
      navItem: [], //轮播每屏数据
      lookList: [], //瀑布流数据
    };
  },
  components: {
    vueWaterfallEasy,
  },
  methods: {
    //获取轮播数据
    async reqWorthSwiper() {
      let result = await reqWorthSwiper();
      this.navList = result.data.navList;
      //console.log(this.navList);
    },
    //生成二维数组
    sliceNavList() {
      for (let i = 0; i < this.navList.length; i += 2) {
        let tempData = [];
        tempData.push(this.navList[i]);
        tempData.push(this.navList[i + 1]);
        this.navItem.push(tempData);
      }
      //console.log(this.navItem);
      //console.log(this.navItem[0]);
    },
    //获取瀑布流数据
    async reqWorthLook() {
      let result = await reqWorthLook();
      this.lookList = [
        ...result.data.result[0].topics,
        ...result.data.result[1].topics,
      ];
      console.log(this.lookList);
    },
  },
  mounted() {
    this.reqWorthSwiper().then(() => {
      this.sliceNavList();
    });
    this.reqWorthLook();
  },
};
</script>

<style lang="less">
.worth {
  padding: 30px 5px;
  margin-bottom: 30px;
  background-color: #eeeeee;
  background-image: url(~@/pages/Worth/images/背景.jpg);
  background-repeat: no-repeat;
  background-size: 100%;
  .title {
    display: flex;
    align-items: flex-end;
    padding: 0 5px;
    .logo {
      width: 60px;
      height: 40px;
    }
    .text {
      font-size: 15px;
      color: #ffffff;
      padding: 5px;
    }
  }
  .swiperBox {
    height: 270px;
    background-color: #ffffff;
    border-radius: 10px;
    margin: 5px;
    .van-swipe {
      loop: false;
      width: 100%;
      height: 100%;
      .van-swipe-item {
        .info {
          img {
            margin-left: 15px;
          }
          text-align: center;
          display: flex;
          flex-direction: column;
          justify-content: center;
          margin: 14px 0px 0px;
          .pic {
            width: 60px;
            height: 60px;
          }
          .main {
            margin: 3px 0;
            font-size: 14px;
            font-weight: 700;
            color: #333333;
          }
          .vice {
            font-size: 12px;
            color: #999999;
          }
        }
      }
      .van-swipe__indicator {
        width: 10px;
        height: 2px;
        margin: 0;
        border-radius: 0;
      }
      .van-swipe__indicator--active {
        background-color: #dd1a21;
      }
    }
  }
  .looksList {
    display: flex;
    flex-direction: row;
    .look {
      display: flex;
      flex-direction: column;
      width: 50%;
      background-color: #ffffff;
      border-radius: 10px;
      margin: 5px;
      .lookImg {
        width: 100%;
        height: auto;
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;
      }
      .lookTitle {
        font-size: 14px;
        color: #333333;
        margin: 5px;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .topics {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 5px;
        font-size: 12px;
        color: #7f7f7f;
        .topicsName {
          display: flex;
          align-items: center;
          .topicsImg {
            width: 24px;
            height: 24px;
            padding-right: 2px;
            border-radius: 100%;
          }
        }
        .readCount {
          display: flex;
          align-items: center;
          .van-icon {
            font-size: 14px;
            padding-right: 2px;
          }
        }
      }
    }
  }
}
</style>